package com.codewsq.factory;

/**
 * 设计模式：简单工厂模式
 */
public class EasyFactoryTest {
    public static void main(String[] args) {
        Car car1 = CarFactory.getCar("奥迪");
        car1.run();
        Car car2 = CarFactory.getCar("比亚迪");
        car2.run();
    }
}

interface Car {
    void run();
}

class Audi implements Car {

    @Override
    public void run() {
        System.out.println("奥迪在跑！");
    }
}

class BYD implements Car {

    @Override
    public void run() {
        System.out.println("比亚迪在跑！");
    }
}

class CarFactory {

    public static Car getCar(String carType) {
        Car car = null;
        switch (carType) {
            case "奥迪":
                car = new Audi();
                break;
            case "比亚迪":
                car = new BYD();
                break;
        }
        return car;
    }

}
